Self-Driving Car Engineer Nanodegree

Deep Learning

Project: Build a Traffic Sign Recognition Classifier

In this notebook, a template is provided for you to implement your functionality in stages, which is required to successfully complete this project. If additional code is required that cannot be included in the notebook, be sure that the Python code is successfully imported and included in your submission if necessary.

Note: Once you have completed all of the code implementations, you need to finalize your work by exporting the iPython Notebook as an HTML document. Before exporting the notebook to html, all of the code cells need to have been run so that reviewers can see the final implementation and output. You can then export the notebook by using the menu above and navigating to \n", "File -> Download as -> HTML (.html). Include the finished document along with this notebook as your submission.

In addition to implementing code, there is a writeup to complete. The writeup should be completed in a separate file, which can be either a markdown file or a pdf document. There is a write up template that can be used to guide the writing process. Completing the code template and writeup template will cover all of the rubric points for this project.

The rubric contains "Stand Out Suggestions" for enhancing the project beyond the minimum requirements. The stand out suggestions are optional. If you decide to pursue the "stand out suggestions", you can include the code in this Ipython notebook and also discuss the results in the writeup file.

Note: Code and Markdown cells can be executed using the Shift + Enter keyboard shortcut. In addition, Markdown cells can be edited by typically double-clicking the cell to enter edit mode.


Step 0: Load The Data

In [1]:
import matplotlib.pyplot as plt
%matplotlib inline

%load_ext autoreload
%autoreload 2

import numpy as np
import pandas as pd
import cv2
from tqdm import tqdm
import sys
import pickle
import tensorflow as tf
from sklearn.utils import shuffle
import tsc_utils as tu
import time
import datetime
In [2]:
# Load pickled data

training_file = 'data/train.p'
validation_file= 'data/valid.p'
testing_file = 'data/test.p'

with open(training_file, mode='rb') as f:
    train = pickle.load(f)
with open(validation_file, mode='rb') as f:
    valid = pickle.load(f)
with open(testing_file, mode='rb') as f:
    test = pickle.load(f)
    
X_train, y_train = train['features'], train['labels']
X_valid, y_valid = valid['features'], valid['labels']
X_test, y_test = test['features'], test['labels']

Step 1: Dataset Summary & Exploration

The pickled data is a dictionary with 4 key/value pairs:

  • 'features' is a 4D array containing raw pixel data of the traffic sign images, (num examples, width, height, channels).
  • 'labels' is a 1D array containing the label/class id of the traffic sign. The file signnames.csv contains id -> name mappings for each id.
  • 'sizes' is a list containing tuples, (width, height) representing the original width and height the image.
  • 'coords' is a list containing tuples, (x1, y1, x2, y2) representing coordinates of a bounding box around the sign in the image. THESE COORDINATES ASSUME THE ORIGINAL IMAGE. THE PICKLED DATA CONTAINS RESIZED VERSIONS (32 by 32) OF THESE IMAGES

Complete the basic data summary below. Use python, numpy and/or pandas methods to calculate the data summary rather than hard coding the results. For example, the pandas shape method might be useful for calculating some of the summary results.

Provide a Basic Summary of the Data Set Using Python, Numpy and/or Pandas

In [3]:
### Replace each question mark with the appropriate value. 
### Use python, pandas or numpy methods rather than hard coding the results

# TODO: Number of training examples
n_train = len(y_train)

# TODO: Number of validation examples
n_validation = len(y_valid)

# TODO: Number of testing examples.
n_test = len(y_test)

# TODO: What's the shape of an traffic sign image?
image_shape = X_train.shape[1:]

# TODO: How many unique classes/labels there are in the dataset.
n_classes = len(set(y_train))

print("Number of training examples =", n_train)
print("Number of validation examples =", n_validation)
print("Number of testing examples =", n_test)
print("Image data shape =", image_shape)
print("Number of classes =", n_classes)
norm_done = False
Number of training examples = 34799
Number of validation examples = 4410
Number of testing examples = 12630
Image data shape = (32, 32, 3)
Number of classes = 43

Include an exploratory visualization of the dataset

Visualize the German Traffic Signs Dataset using the pickled file(s). This is open ended, suggestions include: plotting traffic sign images, plotting the count of each sign, etc.

The Matplotlib examples and gallery pages are a great resource for doing visualizations in Python.

NOTE: It's recommended you start with something simple first. If you wish to do more, come back to it after you've completed the rest of the sections. It can be interesting to look at the distribution of classes in the training, validation and test set. Is the distribution the same? Are there more examples of some classes than others?

In [4]:
### Data exploration visualization code goes here.
### Feel free to use as many code cells as needed.
sign_df = pd.read_csv('signnames.csv')
df = pd.Series(y_train).value_counts().to_frame('label_counts')
sign_df = pd.merge(sign_df, df, left_on='ClassId', right_index=True)
sign_df['label_freq'] = sign_df['label_counts'] / sign_df['label_counts'].sum() 
sign_df['label_freq_normed'] = sign_df['label_freq'] / sign_df['label_freq'].mean()
sign_df = sign_df.set_index('ClassId')

def plot_data():
    plt.figure(figsize=(20,4))
    a = 0.8
    plt.hist(y_train, alpha=a, bins=np.arange(n_classes+1)-0.5)
    plt.hist(y_test, alpha=a, bins=np.arange(n_classes+1)-0.5)
    plt.hist(y_valid, alpha=a, bins=np.arange(n_classes+1)-0.5)
    plt.xticks(range(n_classes), sign_df['SignName'], rotation='vertical')
    plt.legend(['train', 'test', 'valid'])
    plt.autoscale(enable=True, axis='x', tight=True)

plot_data()
In [5]:
np.random.seed(1019)
N = n_classes
M = 15
img_canvas = []
img_canvas_gray = []
clahe = tu.DEFAULT_CLAHE
for i in range(n_classes):
    X_select = X_train[y_train == i]
    
    idx = np.random.choice(np.arange(X_select.shape[0]), M)
    img_canvas = np.concatenate(X_select[idx], axis=1)
    gray_images = [cv2.cvtColor(x, cv2.COLOR_BGR2GRAY) for x in X_select[idx]]
    img_canvas_gray = np.concatenate(gray_images, axis=1)
    
    gray_images_equ = [cv2.equalizeHist(x) for x in gray_images]
    img_canvas_equ = np.concatenate(gray_images_equ, axis=1)
    
    gray_images_Lequ = [clahe.apply(x) for x in gray_images]
    img_canvas_Lequ = np.concatenate(gray_images_Lequ, axis=1)
    
    gray_images_Lequ_normed = [(x-128.)/128 for x in gray_images_Lequ]
    img_canvas_Lequ_normed = np.concatenate(gray_images_Lequ_normed, axis=1)
    
    gray_images_Lequ_normed_v2 = [(x-x.mean())/x.std() for x in gray_images_Lequ]
    img_canvas_Lequ_normed_v2 = np.concatenate(gray_images_Lequ_normed_v2, axis=1)
    
    N = 6
    
    plt.figure(figsize=(20,6))
    plt.subplot(N,1,1)
    plt.imshow(img_canvas)
    plt.xticks([])
    plt.yticks([])
    plt.title('Class {}: {}, N_sampes: {}, Rel_freq: {:.2}'.format(i, sign_df.loc[i]['SignName'], sign_df.loc[i]['label_counts'],sign_df.loc[i]['label_freq_normed']))
    
    if i == n_classes-1:
        plt.subplot(N,1,2)
        plt.imshow(img_canvas_gray, cmap='gray')
        plt.xticks([])
        plt.yticks([])

        plt.subplot(N,1,3)
        plt.imshow(img_canvas_equ, cmap='gray')
        plt.xticks([])
        plt.yticks([])

        plt.subplot(N,1,4)
        plt.imshow(img_canvas_Lequ, cmap='gray')
        plt.xticks([])
        plt.yticks([])

        plt.subplot(N,1,5)
        plt.imshow(img_canvas_Lequ_normed, cmap='gray')
        plt.xticks([])
        plt.yticks([])

        plt.subplot(N,1,6)
        plt.imshow(img_canvas_Lequ_normed_v2, cmap='gray')
        plt.xticks([])
        plt.yticks([])

    plt.show()

Dataset augmentation

In [6]:
# demonstraing a set of functions for image transformation
test_img = X_train[100]
plt.figure(figsize=(20,10))
N = 7
i=1
plt.subplot(1, N, i)
plt.imshow(test_img)
plt.title('original')

i+=1
plt.subplot(1, N, i)
plt.imshow(tu.resize_img(test_img, scale=1.15))
plt.title('scaled')

i+=1
plt.subplot(1, N, i)
plt.imshow(tu.rotate_img(test_img, angle=25))
plt.title('rotated')

i+=1
plt.subplot(1, N, i)
plt.imshow(tu.shift_img(test_img, dx=5, dy=2))
plt.title('shifted')

i+=1
b, s = tu.blur_and_sharpen_img(test_img, kernel=(5,5), factor=0.8)
plt.subplot(1, N, i)
plt.imshow(b)
plt.title('blur')
i+=1
plt.subplot(1, N, i)
plt.imshow(s)
plt.title('sharpen')

i+=1
plt.subplot(1, N, i)
np.random.seed(1019)
plt.imshow(tu.distort_img(test_img, d_limit=5))
plt.title('random distort')

plt.show()
In [7]:
# merge X_train and X_valid

# print(X_train.shape)
# X_train = np.concatenate([X_train, X_valid], axis=0)
# print(X_train.shape)
# print(y_train.shape)
# y_train = np.concatenate([y_train, y_valid], axis=0)
# print(y_train.shape)
In [8]:
flip_extend = True
augment_data = True
In [9]:
if flip_extend:
    X_train, y_train = tu.flip_extend(X_train, y_train)
    X_valid, y_valid = tu.flip_extend(X_valid, y_valid)
Input sizes:  (34799, 32, 32, 3) (34799,)
100%|██████████████████████████████████████████████████████████████████████████████████| 43/43 [00:03<00:00,  9.27it/s]
Output sizes:  (59788, 32, 32, 3) (59788,)
Input sizes:  (4410, 32, 32, 3) (4410,)
100%|█████████████████████████████████████████████████████████████████████████████████| 43/43 [00:00<00:00, 118.47it/s]
Output sizes:  (7590, 32, 32, 3) (7590,)
In [10]:
# from sklearn.model_selection import train_test_split
# X_train, X_valid, y_train, y_valid = train_test_split(X_train, y_train, test_size = 0.2, random_state=42)
# print(X_train.shape, y_train.shape)
# print(X_valid.shape, y_valid.shape)
In [11]:
if augment_data:
    setting = dict(distort=True,
                   resize=True, 
                   rotate=True, 
                   shift=True, 
                   blursharpen=True)
    boost=False
    
    if boost:
        target_y = [30, 18, 21]
        N_copy = 10
        X_train_boost, y_train_boost = tu.augment_data(X_train, y_train, N_copy=N_copy, target_y=target_y, **setting)
        X_valid_boost, y_valid_boost = tu.augment_data(X_valid, y_valid, N_copy=N_copy, target_y=target_y, **setting)
    
    X_train, y_train = tu.augment_data(X_train, y_train, **setting)
    X_valid, y_valid = tu.augment_data(X_valid, y_valid, **setting)
    
    if boost:
        X_train = np.concatenate([X_train, X_train_boost], axis=0)
        y_train = np.concatenate([y_train, y_train_boost], axis=0)
        X_valid = np.concatenate([X_valid, X_valid_boost], axis=0)
        y_valid = np.concatenate([y_valid, y_valid_boost], axis=0)
========= augment_data() arguments: =========
distort = True
resize = True
rotate = True
shift = True
blursharpen = True
N_copy = 1
target_y = None
=============================================
Input shapes:  (59788, 32, 32, 3) (59788,)
100%|██████████████████████████████████████████████████████████████████████████| 59788/59788 [00:22<00:00, 2694.05it/s]
Output shapes:  (1016396, 32, 32, 3) (1016396,)
========= augment_data() arguments: =========
distort = True
resize = True
rotate = True
shift = True
blursharpen = True
N_copy = 1
target_y = None
=============================================
Input shapes:  (7590, 32, 32, 3) (7590,)
100%|████████████████████████████████████████████████████████████████████████████| 7590/7590 [00:02<00:00, 2702.04it/s]
Output shapes:  (129030, 32, 32, 3) (129030,)
In [12]:
print(X_train.shape, y_train.shape)
print(X_valid.shape, y_valid.shape)
(1016396, 32, 32, 3) (1016396,)
(129030, 32, 32, 3) (129030,)

Step 2: Design and Test a Model Architecture

Design and implement a deep learning model that learns to recognize traffic signs. Train and test your model on the German Traffic Sign Dataset.

The LeNet-5 implementation shown in the classroom at the end of the CNN lesson is a solid starting point. You'll have to change the number of classes and possibly the preprocessing, but aside from that it's plug and play!

With the LeNet-5 solution from the lecture, you should expect a validation set accuracy of about 0.89. To meet specifications, the validation set accuracy will need to be at least 0.93. It is possible to get an even higher accuracy, but 0.93 is the minimum for a successful project submission.

There are various aspects to consider when thinking about this problem:

  • Neural network architecture (is the network over or underfitting?)
  • Play around preprocessing techniques (normalization, rgb to grayscale, etc)
  • Number of examples per label (some have more than others).
  • Generate fake data.

Here is an example of a published baseline model on this problem. It's not required to be familiar with the approach used in the paper but, it's good practice to try to read papers like these.

Pre-process the Data Set (normalization, grayscale, etc.)

Minimally, the image data should be normalized so that the data has mean zero and equal variance. For image data, (pixel - 128)/ 128 is a quick way to approximately normalize the data and can be used in this project.

Other pre-processing steps are optional. You can try different techniques to see if it improves performance.

Use the code cell (or multiple code cells, if necessary) to implement the first step of your project.

In [13]:
### Preprocess the data here. It is required to normalize the data. Other preprocessing steps could include 
### converting to grayscale, etc.
### Feel free to use as many code cells as needed.

# color conversion, hist equalization and normalization
X_train = tu.preprocess_data(X_train)
X_valid = tu.preprocess_data(X_valid)
X_test = tu.preprocess_data(X_test)
norm_done = True
Input shapes:  (1016396, 32, 32, 3)
Using gray
100%|█████████████████████████████████████████████████████████████████████| 1016396/1016396 [01:24<00:00, 11986.02it/s]
Output shapes:  (1016396, 32, 32, 1)
Input shapes:  (129030, 32, 32, 3)
Using gray
100%|███████████████████████████████████████████████████████████████████████| 129030/129030 [00:10<00:00, 12011.66it/s]
Output shapes:  (129030, 32, 32, 1)
Input shapes:  (12630, 32, 32, 3)
Using gray
100%|█████████████████████████████████████████████████████████████████████████| 12630/12630 [00:01<00:00, 12152.85it/s]
Output shapes:  (12630, 32, 32, 1)
In [14]:
if X_train.nbytes > 4e9:
    X_train = X_train.astype(np.float32)
    X_valid = X_valid.astype(np.float32)
print(X_train.nbytes)
4163158016
In [15]:
test_preprocessed_dataset_file = 'data/test_preprocessed.p'
print(test_preprocessed_dataset_file)
pickle.dump({
        "features" : X_test,
        "labels" : y_test
    }, open(test_preprocessed_dataset_file, "wb" ) )


flip_str = ''
augment_str = ''
if flip_extend:
    flip_str = 'flip_extended_'

if augment_data:
    augment_str = 'augmented_'


train_preprocessed_dataset_file = 'data/train_{}{}preprocessed.p'.format(flip_str, augment_str)
print(train_preprocessed_dataset_file)
pickle.dump({
        "features" : X_train,
        "labels" : y_train
    }, open(train_preprocessed_dataset_file, "wb" ) )

valid_preprocessed_dataset_file = 'data/valid_{}{}preprocessed.p'.format(flip_str, augment_str)
print(valid_preprocessed_dataset_file)
pickle.dump({
        "features" : X_valid,
        "labels" : y_valid
    }, open(valid_preprocessed_dataset_file, "wb" ) )
data/test_preprocessed.p
data/train_flip_extended_augmented_preprocessed.p
data/valid_flip_extended_augmented_preprocessed.p
In [16]:
np.random.seed(1019)

plt.figure(figsize=(35,10))
N = 35
M = 10

X_tmp = X_train

img_canvas = []
for i in range(M):
    idx = np.random.choice(np.arange(X_tmp.shape[0]), N)
    img_canvas.append(np.concatenate(X_tmp[idx], axis=1))

img_canvas = np.concatenate(img_canvas, axis=0)

if img_canvas.shape[-1]==1:
    plt.imshow(img_canvas.squeeze(), cmap='gray')
elif img_canvas.shape[-1]==3:
    plt.imshow(img_canvas)
else:
    plt.imshow(img_canvas[:,:,0], cmap='gray')

Model Architecture

In [17]:
# load data

# original set
train_fname = 'data/train_preprocessed.p'
valid_fname = 'data/valid_preprocessed.p'

# augmented set
train_fname_FA = 'data/train_flip_extended_augmented_preprocessed.p'
valid_fname_FA = 'data/valid_flip_extended_augmented_preprocessed.p'

# flip extended set
train_fname_F = 'data/train_flip_extended_preprocessed.p'
valid_fname_F = 'data/valid_flip_extended_preprocessed.p'


test_fname = 'data/test_preprocessed.p'
In [18]:
X_train, y_train = tu.load_pickled_data(train_fname_F, columns = ['features', 'labels'])
X_valid, y_valid = tu.load_pickled_data(valid_fname_F, columns = ['features', 'labels'])
X_test, y_test = tu.load_pickled_data(test_fname, columns = ['features', 'labels'])
print(X_train.shape, y_train.shape)
print(X_valid.shape, y_valid.shape)
print(X_test.shape, y_test.shape)
(59788, 32, 32, 1) (59788,)
(7590, 32, 32, 1) (7590,)
(12630, 32, 32, 1) (12630,)
In [19]:
_ = tu.train_model(X_train, y_train, X_valid, y_valid, X_test, y_test,
                  model=tu.lenet, model_params=tu.params_orig_lenet)
========= train_model() arguments: ==========
resuming = False
model = <function lenet at 0x000001E2F2D91E18>
model_params = {'conv2_d': 16, 'fc3_size': 120, 'fc4_size': 84, 'conv2_k': 5, 'conv1_d': 6, 'conv1_k': 5, 'model_name': 'lenet', 'fc3_p': 0.5, 'num_classes': 43, 'fc4_p': 0.5, 'conv2_p': 0.95, 'conv1_p': 0.95}
learning_rate = 0.001
max_epochs = 100
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
=============================================
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_6_conv1_k_5_conv1_p_0.95_conv2_d_16_conv2_k_5_conv2_p_0.95_fc3_p_0.5_fc3_size_120_fc4_p_0.5_fc4_size_84
{'conv2_d': 16, 'fc3_size': 120, 'fc4_size': 84, 'conv2_k': 5, 'conv1_d': 6, 'conv1_k': 5, 'model_name': 'lenet', 'fc3_p': 0.5, 'num_classes': 43, 'fc4_p': 0.5, 'conv2_p': 0.95, 'conv1_p': 0.95}
lenet pool2 reshaped size:  [None, 1024]
================= TRAINING ==================
 Timestamp: 2017/06/09 09:55:58
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:04<00:00, 54.89it/s]
-------------- EPOCH    0/100 --------------
     Train loss: 0.92223141, accuracy: 74.74%
Validation loss: 1.03625287, accuracy: 70.75%
      Best loss: inf at epoch 0
   Elapsed time: 00:00:10
      Timestamp: 2017/06/09 09:56:04
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 71.99it/s]
-------------- EPOCH    1/100 --------------
     Train loss: 0.44451094, accuracy: 87.07%
Validation loss: 0.54138371, accuracy: 83.57%
      Best loss: 1.03625287 at epoch 0
   Elapsed time: 00:00:15
      Timestamp: 2017/06/09 09:56:09
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.14it/s]
-------------- EPOCH    2/100 --------------
     Train loss: 0.26420701, accuracy: 93.01%
Validation loss: 0.35292487, accuracy: 89.33%
      Best loss: 0.54138371 at epoch 1
   Elapsed time: 00:00:20
      Timestamp: 2017/06/09 09:56:14
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.35it/s]
-------------- EPOCH    3/100 --------------
     Train loss: 0.18811034, accuracy: 95.52%
Validation loss: 0.28833843, accuracy: 91.55%
      Best loss: 0.35292487 at epoch 2
   Elapsed time: 00:00:25
      Timestamp: 2017/06/09 09:56:19
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 71.94it/s]
-------------- EPOCH    4/100 --------------
     Train loss: 0.14113133, accuracy: 97.00%
Validation loss: 0.23975855, accuracy: 93.37%
      Best loss: 0.28833843 at epoch 3
   Elapsed time: 00:00:30
      Timestamp: 2017/06/09 09:56:24
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.16it/s]
-------------- EPOCH    5/100 --------------
     Train loss: 0.10685136, accuracy: 97.66%
Validation loss: 0.20750208, accuracy: 94.20%
      Best loss: 0.23975855 at epoch 4
   Elapsed time: 00:00:35
      Timestamp: 2017/06/09 09:56:29
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.57it/s]
-------------- EPOCH    6/100 --------------
     Train loss: 0.08629605, accuracy: 98.10%
Validation loss: 0.17855363, accuracy: 94.60%
      Best loss: 0.20750208 at epoch 5
   Elapsed time: 00:00:40
      Timestamp: 2017/06/09 09:56:34
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.05it/s]
-------------- EPOCH    7/100 --------------
     Train loss: 0.07092102, accuracy: 98.60%
Validation loss: 0.16737571, accuracy: 95.44%
      Best loss: 0.17855363 at epoch 6
   Elapsed time: 00:00:45
      Timestamp: 2017/06/09 09:56:39
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.32it/s]
-------------- EPOCH    8/100 --------------
     Train loss: 0.06026585, accuracy: 98.68%
Validation loss: 0.16737493, accuracy: 95.05%
      Best loss: 0.16737571 at epoch 7
   Elapsed time: 00:00:50
      Timestamp: 2017/06/09 09:56:44
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.39it/s]
-------------- EPOCH    9/100 --------------
     Train loss: 0.04759235, accuracy: 99.05%
Validation loss: 0.13564470, accuracy: 96.02%
      Best loss: 0.16737493 at epoch 8
   Elapsed time: 00:00:55
      Timestamp: 2017/06/09 09:56:49
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.14it/s]
-------------- EPOCH   10/100 --------------
     Train loss: 0.04802718, accuracy: 99.02%
Validation loss: 0.14073165, accuracy: 95.90%
      Best loss: 0.13564470 at epoch 9
   Elapsed time: 00:01:00
      Timestamp: 2017/06/09 09:56:54
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.84it/s]
-------------- EPOCH   11/100 --------------
     Train loss: 0.03797019, accuracy: 99.18%
Validation loss: 0.14121976, accuracy: 96.05%
      Best loss: 0.13564470 at epoch 9
   Elapsed time: 00:01:04
      Timestamp: 2017/06/09 09:56:58
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.61it/s]
-------------- EPOCH   12/100 --------------
     Train loss: 0.03633892, accuracy: 99.26%
Validation loss: 0.13583950, accuracy: 96.05%
      Best loss: 0.13564470 at epoch 9
   Elapsed time: 00:01:09
      Timestamp: 2017/06/09 09:57:02
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.96it/s]
-------------- EPOCH   13/100 --------------
     Train loss: 0.03186271, accuracy: 99.36%
Validation loss: 0.13370131, accuracy: 96.17%
      Best loss: 0.13564470 at epoch 9
   Elapsed time: 00:01:13
      Timestamp: 2017/06/09 09:57:07
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.52it/s]
-------------- EPOCH   14/100 --------------
     Train loss: 0.02772952, accuracy: 99.45%
Validation loss: 0.13241175, accuracy: 96.09%
      Best loss: 0.13370131 at epoch 13
   Elapsed time: 00:01:18
      Timestamp: 2017/06/09 09:57:12
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.53it/s]
-------------- EPOCH   15/100 --------------
     Train loss: 0.02583036, accuracy: 99.42%
Validation loss: 0.11884834, accuracy: 96.30%
      Best loss: 0.13241175 at epoch 14
   Elapsed time: 00:01:23
      Timestamp: 2017/06/09 09:57:17
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.45it/s]
-------------- EPOCH   16/100 --------------
     Train loss: 0.02366489, accuracy: 99.52%
Validation loss: 0.11971744, accuracy: 96.60%
      Best loss: 0.11884834 at epoch 15
   Elapsed time: 00:01:28
      Timestamp: 2017/06/09 09:57:22
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 73.19it/s]
-------------- EPOCH   17/100 --------------
     Train loss: 0.01970052, accuracy: 99.61%
Validation loss: 0.11006528, accuracy: 96.71%
      Best loss: 0.11884834 at epoch 15
   Elapsed time: 00:01:33
      Timestamp: 2017/06/09 09:57:26
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.31it/s]
-------------- EPOCH   18/100 --------------
     Train loss: 0.01966100, accuracy: 99.65%
Validation loss: 0.12368710, accuracy: 96.53%
      Best loss: 0.11006528 at epoch 17
   Elapsed time: 00:01:38
      Timestamp: 2017/06/09 09:57:31
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.95it/s]
-------------- EPOCH   19/100 --------------
     Train loss: 0.01757546, accuracy: 99.66%
Validation loss: 0.10627640, accuracy: 96.96%
      Best loss: 0.11006528 at epoch 17
   Elapsed time: 00:01:42
      Timestamp: 2017/06/09 09:57:36
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 71.92it/s]
-------------- EPOCH   20/100 --------------
     Train loss: 0.01782695, accuracy: 99.61%
Validation loss: 0.10889493, accuracy: 96.94%
      Best loss: 0.10627640 at epoch 19
   Elapsed time: 00:01:47
      Timestamp: 2017/06/09 09:57:41
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.93it/s]
-------------- EPOCH   21/100 --------------
     Train loss: 0.01425038, accuracy: 99.69%
Validation loss: 0.10736962, accuracy: 96.88%
      Best loss: 0.10627640 at epoch 19
   Elapsed time: 00:01:52
      Timestamp: 2017/06/09 09:57:45
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.87it/s]
-------------- EPOCH   22/100 --------------
     Train loss: 0.01659414, accuracy: 99.66%
Validation loss: 0.10832488, accuracy: 96.85%
      Best loss: 0.10627640 at epoch 19
   Elapsed time: 00:01:56
      Timestamp: 2017/06/09 09:57:50
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.85it/s]
-------------- EPOCH   23/100 --------------
     Train loss: 0.01358422, accuracy: 99.75%
Validation loss: 0.10288431, accuracy: 96.96%
      Best loss: 0.10627640 at epoch 19
   Elapsed time: 00:02:01
      Timestamp: 2017/06/09 09:57:54
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.21it/s]
-------------- EPOCH   24/100 --------------
     Train loss: 0.01211036, accuracy: 99.78%
Validation loss: 0.10310320, accuracy: 97.23%
      Best loss: 0.10288431 at epoch 23
   Elapsed time: 00:02:06
      Timestamp: 2017/06/09 09:57:59
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.67it/s]
-------------- EPOCH   25/100 --------------
     Train loss: 0.01265472, accuracy: 99.78%
Validation loss: 0.10238408, accuracy: 96.98%
      Best loss: 0.10288431 at epoch 23
   Elapsed time: 00:02:10
      Timestamp: 2017/06/09 09:58:04
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.09it/s]
-------------- EPOCH   26/100 --------------
     Train loss: 0.01129811, accuracy: 99.81%
Validation loss: 0.10265648, accuracy: 97.22%
      Best loss: 0.10238408 at epoch 25
   Elapsed time: 00:02:15
      Timestamp: 2017/06/09 09:58:08
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.64it/s]
-------------- EPOCH   27/100 --------------
     Train loss: 0.00908932, accuracy: 99.83%
Validation loss: 0.09423115, accuracy: 97.40%
      Best loss: 0.10238408 at epoch 25
   Elapsed time: 00:02:19
      Timestamp: 2017/06/09 09:58:13
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.04it/s]
-------------- EPOCH   28/100 --------------
     Train loss: 0.00891153, accuracy: 99.86%
Validation loss: 0.09929009, accuracy: 97.21%
      Best loss: 0.09423115 at epoch 27
   Elapsed time: 00:02:24
      Timestamp: 2017/06/09 09:58:18
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.38it/s]
-------------- EPOCH   29/100 --------------
     Train loss: 0.00995976, accuracy: 99.83%
Validation loss: 0.09211503, accuracy: 97.46%
      Best loss: 0.09423115 at epoch 27
   Elapsed time: 00:02:29
      Timestamp: 2017/06/09 09:58:22
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 71.87it/s]
-------------- EPOCH   30/100 --------------
     Train loss: 0.01012282, accuracy: 99.84%
Validation loss: 0.09542178, accuracy: 97.29%
      Best loss: 0.09211503 at epoch 29
   Elapsed time: 00:02:34
      Timestamp: 2017/06/09 09:58:27
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.39it/s]
-------------- EPOCH   31/100 --------------
     Train loss: 0.00750687, accuracy: 99.89%
Validation loss: 0.09662788, accuracy: 97.36%
      Best loss: 0.09211503 at epoch 29
   Elapsed time: 00:02:38
      Timestamp: 2017/06/09 09:58:32
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.35it/s]
-------------- EPOCH   32/100 --------------
     Train loss: 0.00859763, accuracy: 99.83%
Validation loss: 0.09989075, accuracy: 97.36%
      Best loss: 0.09211503 at epoch 29
   Elapsed time: 00:02:43
      Timestamp: 2017/06/09 09:58:36
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.10it/s]
-------------- EPOCH   33/100 --------------
     Train loss: 0.00711584, accuracy: 99.88%
Validation loss: 0.09024643, accuracy: 97.39%
      Best loss: 0.09211503 at epoch 29
   Elapsed time: 00:02:47
      Timestamp: 2017/06/09 09:58:41
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.21it/s]
-------------- EPOCH   34/100 --------------
     Train loss: 0.00760766, accuracy: 99.87%
Validation loss: 0.09046729, accuracy: 97.17%
      Best loss: 0.09024643 at epoch 33
   Elapsed time: 00:02:52
      Timestamp: 2017/06/09 09:58:46
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.59it/s]
-------------- EPOCH   35/100 --------------
     Train loss: 0.00743308, accuracy: 99.87%
Validation loss: 0.09365678, accuracy: 97.33%
      Best loss: 0.09024643 at epoch 33
   Elapsed time: 00:02:57
      Timestamp: 2017/06/09 09:58:50
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.59it/s]
-------------- EPOCH   36/100 --------------
     Train loss: 0.00615238, accuracy: 99.90%
Validation loss: 0.09046318, accuracy: 97.47%
      Best loss: 0.09024643 at epoch 33
   Elapsed time: 00:03:01
      Timestamp: 2017/06/09 09:58:55
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.59it/s]
-------------- EPOCH   37/100 --------------
     Train loss: 0.00569765, accuracy: 99.91%
Validation loss: 0.09530729, accuracy: 97.44%
      Best loss: 0.09024643 at epoch 33
   Elapsed time: 00:03:06
      Timestamp: 2017/06/09 09:58:59
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.22it/s]
-------------- EPOCH   38/100 --------------
     Train loss: 0.00571385, accuracy: 99.90%
Validation loss: 0.08855662, accuracy: 97.63%
      Best loss: 0.09024643 at epoch 33
   Elapsed time: 00:03:10
      Timestamp: 2017/06/09 09:59:04
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 71.85it/s]
-------------- EPOCH   39/100 --------------
     Train loss: 0.00562647, accuracy: 99.91%
Validation loss: 0.09681964, accuracy: 97.34%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:15
      Timestamp: 2017/06/09 09:59:09
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.61it/s]
-------------- EPOCH   40/100 --------------
     Train loss: 0.00577243, accuracy: 99.90%
Validation loss: 0.09173629, accuracy: 97.42%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:20
      Timestamp: 2017/06/09 09:59:13
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.69it/s]
-------------- EPOCH   41/100 --------------
     Train loss: 0.00568478, accuracy: 99.92%
Validation loss: 0.09907908, accuracy: 97.35%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:24
      Timestamp: 2017/06/09 09:59:18
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.53it/s]
-------------- EPOCH   42/100 --------------
     Train loss: 0.00507370, accuracy: 99.92%
Validation loss: 0.09496997, accuracy: 97.46%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:29
      Timestamp: 2017/06/09 09:59:22
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.55it/s]
-------------- EPOCH   43/100 --------------
     Train loss: 0.00517465, accuracy: 99.92%
Validation loss: 0.09686700, accuracy: 97.42%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:33
      Timestamp: 2017/06/09 09:59:27
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.39it/s]
-------------- EPOCH   44/100 --------------
     Train loss: 0.00524502, accuracy: 99.89%
Validation loss: 0.10192576, accuracy: 97.38%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:38
      Timestamp: 2017/06/09 09:59:31
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.49it/s]
-------------- EPOCH   45/100 --------------
     Train loss: 0.00456019, accuracy: 99.93%
Validation loss: 0.09771077, accuracy: 97.56%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:42
      Timestamp: 2017/06/09 09:59:35
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.40it/s]
-------------- EPOCH   46/100 --------------
     Train loss: 0.00447160, accuracy: 99.93%
Validation loss: 0.08418058, accuracy: 97.73%
      Best loss: 0.08855662 at epoch 38
   Elapsed time: 00:03:46
      Timestamp: 2017/06/09 09:59:40
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.15it/s]
-------------- EPOCH   47/100 --------------
     Train loss: 0.00463388, accuracy: 99.91%
Validation loss: 0.08956305, accuracy: 97.59%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:03:51
      Timestamp: 2017/06/09 09:59:45
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.54it/s]
-------------- EPOCH   48/100 --------------
     Train loss: 0.00471744, accuracy: 99.93%
Validation loss: 0.10247313, accuracy: 97.38%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:03:56
      Timestamp: 2017/06/09 09:59:49
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.54it/s]
-------------- EPOCH   49/100 --------------
     Train loss: 0.00378333, accuracy: 99.94%
Validation loss: 0.08717868, accuracy: 97.79%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:00
      Timestamp: 2017/06/09 09:59:54
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.54it/s]
-------------- EPOCH   50/100 --------------
     Train loss: 0.00418176, accuracy: 99.92%
Validation loss: 0.09944865, accuracy: 97.44%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:05
      Timestamp: 2017/06/09 09:59:58
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.52it/s]
-------------- EPOCH   51/100 --------------
     Train loss: 0.00423665, accuracy: 99.94%
Validation loss: 0.09278868, accuracy: 97.62%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:09
      Timestamp: 2017/06/09 10:00:03
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.45it/s]
-------------- EPOCH   52/100 --------------
     Train loss: 0.00510311, accuracy: 99.92%
Validation loss: 0.09077395, accuracy: 97.81%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:14
      Timestamp: 2017/06/09 10:00:07
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.67it/s]
-------------- EPOCH   53/100 --------------
     Train loss: 0.00384869, accuracy: 99.96%
Validation loss: 0.09665021, accuracy: 97.68%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:18
      Timestamp: 2017/06/09 10:00:12
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.60it/s]
-------------- EPOCH   54/100 --------------
     Train loss: 0.00401438, accuracy: 99.94%
Validation loss: 0.09692102, accuracy: 97.55%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:23
      Timestamp: 2017/06/09 10:00:16
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.55it/s]
-------------- EPOCH   55/100 --------------
     Train loss: 0.00341258, accuracy: 99.96%
Validation loss: 0.09460094, accuracy: 97.63%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:27
      Timestamp: 2017/06/09 10:00:21
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.51it/s]
-------------- EPOCH   56/100 --------------
     Train loss: 0.00353342, accuracy: 99.96%
Validation loss: 0.07891253, accuracy: 97.83%
      Best loss: 0.08418058 at epoch 46
   Elapsed time: 00:04:32
      Timestamp: 2017/06/09 10:00:25
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.05it/s]
-------------- EPOCH   57/100 --------------
     Train loss: 0.00302894, accuracy: 99.96%
Validation loss: 0.09059565, accuracy: 97.80%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:04:37
      Timestamp: 2017/06/09 10:00:30
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.50it/s]
-------------- EPOCH   58/100 --------------
     Train loss: 0.00394179, accuracy: 99.94%
Validation loss: 0.08599873, accuracy: 97.80%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:04:41
      Timestamp: 2017/06/09 10:00:35
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.41it/s]
-------------- EPOCH   59/100 --------------
     Train loss: 0.00379047, accuracy: 99.94%
Validation loss: 0.09088039, accuracy: 97.76%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:04:45
      Timestamp: 2017/06/09 10:00:39
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.59it/s]
-------------- EPOCH   60/100 --------------
     Train loss: 0.00357278, accuracy: 99.95%
Validation loss: 0.09024511, accuracy: 97.65%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:04:50
      Timestamp: 2017/06/09 10:00:43
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.66it/s]
-------------- EPOCH   61/100 --------------
     Train loss: 0.00373842, accuracy: 99.94%
Validation loss: 0.09680380, accuracy: 97.73%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:04:54
      Timestamp: 2017/06/09 10:00:48
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.78it/s]
-------------- EPOCH   62/100 --------------
     Train loss: 0.00364235, accuracy: 99.95%
Validation loss: 0.08847890, accuracy: 97.76%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:04:59
      Timestamp: 2017/06/09 10:00:52
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.60it/s]
-------------- EPOCH   63/100 --------------
     Train loss: 0.00383611, accuracy: 99.94%
Validation loss: 0.10172281, accuracy: 97.58%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:05:03
      Timestamp: 2017/06/09 10:00:57
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.62it/s]
-------------- EPOCH   64/100 --------------
     Train loss: 0.00325546, accuracy: 99.95%
Validation loss: 0.10006871, accuracy: 97.43%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:05:08
      Timestamp: 2017/06/09 10:01:01
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.98it/s]
-------------- EPOCH   65/100 --------------
     Train loss: 0.00304353, accuracy: 99.97%
Validation loss: 0.09040279, accuracy: 97.69%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:05:12
      Timestamp: 2017/06/09 10:01:06
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.43it/s]
-------------- EPOCH   66/100 --------------
     Train loss: 0.00335310, accuracy: 99.95%
Validation loss: 0.10908758, accuracy: 97.34%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:05:17
      Timestamp: 2017/06/09 10:01:10
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:03<00:00, 72.47it/s]
-------------- EPOCH   67/100 --------------
     Train loss: 0.00274250, accuracy: 99.96%
Validation loss: 0.09697558, accuracy: 97.56%
      Best loss: 0.07891253 at epoch 56
   Elapsed time: 00:05:21
      Timestamp: 2017/06/09 10:01:15
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_6_conv1_k_5_conv1_p_0.95_conv2_d_16_conv2_k_5_conv2_p_0.95_fc3_p_0.5_fc3_size_120_fc4_p_0.5_fc4_size_84\best_epoch
Early stopping.
Best monitored loss was 0.07891253 at epoch 56.
=============================================
 Valid loss: 0.07891253, accuracy = 97.83%)
 Test loss: 0.18516677, accuracy = 95.91%)
 Total time: 00:05:22
  Timestamp: 2017/06/09 10:01:15
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_6_conv1_k_5_conv1_p_0.95_conv2_d_16_conv2_k_5_conv2_p_0.95_fc3_p_0.5_fc3_size_120_fc4_p_0.5_fc4_size_84\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_6_conv1_k_5_conv1_p_0.95_conv2_d_16_conv2_k_5_conv2_p_0.95_fc3_p_0.5_fc3_size_120_fc4_p_0.5_fc4_size_84\training_history.npz
In [20]:
_ = tu.train_model(X_train, y_train, X_valid, y_valid, X_test, y_test,
                  model=tu.lenet, model_params=tu.params_big_lenet)
========= train_model() arguments: ==========
resuming = False
model = <function lenet at 0x000001E2F2D91E18>
model_params = {'conv2_d': 64, 'fc3_size': 480, 'fc4_size': 252, 'conv2_k': 5, 'conv1_d': 24, 'conv1_k': 5, 'model_name': 'lenet', 'fc3_p': 0.5, 'num_classes': 43, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.8}
learning_rate = 0.001
max_epochs = 100
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
=============================================
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_24_conv1_k_5_conv1_p_0.8_conv2_d_64_conv2_k_5_conv2_p_0.8_fc3_p_0.5_fc3_size_480_fc4_p_0.5_fc4_size_252
{'conv2_d': 64, 'fc3_size': 480, 'fc4_size': 252, 'conv2_k': 5, 'conv1_d': 24, 'conv1_k': 5, 'model_name': 'lenet', 'fc3_p': 0.5, 'num_classes': 43, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.8}
lenet pool2 reshaped size:  [None, 4096]
================= TRAINING ==================
 Timestamp: 2017/06/09 10:01:17
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.16it/s]
-------------- EPOCH    0/100 --------------
     Train loss: 0.14140983, accuracy: 96.47%
Validation loss: 0.24562880, accuracy: 93.07%
      Best loss: inf at epoch 0
   Elapsed time: 00:00:12
      Timestamp: 2017/06/09 10:01:28
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.89it/s]
-------------- EPOCH    1/100 --------------
     Train loss: 0.03306870, accuracy: 99.20%
Validation loss: 0.10616406, accuracy: 96.86%
      Best loss: 0.24562880 at epoch 0
   Elapsed time: 00:00:24
      Timestamp: 2017/06/09 10:01:40
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.96it/s]
-------------- EPOCH    2/100 --------------
     Train loss: 0.01441176, accuracy: 99.71%
Validation loss: 0.07471420, accuracy: 97.71%
      Best loss: 0.10616406 at epoch 1
   Elapsed time: 00:00:36
      Timestamp: 2017/06/09 10:01:52
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.96it/s]
-------------- EPOCH    3/100 --------------
     Train loss: 0.00856732, accuracy: 99.81%
Validation loss: 0.08089339, accuracy: 97.54%
      Best loss: 0.07471420 at epoch 2
   Elapsed time: 00:00:48
      Timestamp: 2017/06/09 10:02:04
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.98it/s]
-------------- EPOCH    4/100 --------------
     Train loss: 0.00443988, accuracy: 99.91%
Validation loss: 0.05625885, accuracy: 98.21%
      Best loss: 0.07471420 at epoch 2
   Elapsed time: 00:00:59
      Timestamp: 2017/06/09 10:02:15
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.99it/s]
-------------- EPOCH    5/100 --------------
     Train loss: 0.00260436, accuracy: 99.96%
Validation loss: 0.06256705, accuracy: 97.97%
      Best loss: 0.05625885 at epoch 4
   Elapsed time: 00:01:11
      Timestamp: 2017/06/09 10:02:27
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.00it/s]
-------------- EPOCH    6/100 --------------
     Train loss: 0.00192484, accuracy: 99.97%
Validation loss: 0.07754979, accuracy: 97.76%
      Best loss: 0.05625885 at epoch 4
   Elapsed time: 00:01:22
      Timestamp: 2017/06/09 10:02:39
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.00it/s]
-------------- EPOCH    7/100 --------------
     Train loss: 0.00222272, accuracy: 99.96%
Validation loss: 0.04554863, accuracy: 98.71%
      Best loss: 0.05625885 at epoch 4
   Elapsed time: 00:01:34
      Timestamp: 2017/06/09 10:02:50
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.95it/s]
-------------- EPOCH    8/100 --------------
     Train loss: 0.00134282, accuracy: 99.96%
Validation loss: 0.06600414, accuracy: 98.13%
      Best loss: 0.04554863 at epoch 7
   Elapsed time: 00:01:46
      Timestamp: 2017/06/09 10:03:02
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.98it/s]
-------------- EPOCH    9/100 --------------
     Train loss: 0.00073317, accuracy: 99.99%
Validation loss: 0.05284464, accuracy: 98.62%
      Best loss: 0.04554863 at epoch 7
   Elapsed time: 00:01:57
      Timestamp: 2017/06/09 10:03:13
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.01it/s]
-------------- EPOCH   10/100 --------------
     Train loss: 0.00074181, accuracy: 99.99%
Validation loss: 0.04891516, accuracy: 98.42%
      Best loss: 0.04554863 at epoch 7
   Elapsed time: 00:02:08
      Timestamp: 2017/06/09 10:03:25
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.01it/s]
-------------- EPOCH   11/100 --------------
     Train loss: 0.00090292, accuracy: 99.97%
Validation loss: 0.05554978, accuracy: 98.46%
      Best loss: 0.04554863 at epoch 7
   Elapsed time: 00:02:20
      Timestamp: 2017/06/09 10:03:36
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.02it/s]
-------------- EPOCH   12/100 --------------
     Train loss: 0.00052612, accuracy: 99.99%
Validation loss: 0.04234268, accuracy: 98.62%
      Best loss: 0.04554863 at epoch 7
   Elapsed time: 00:02:31
      Timestamp: 2017/06/09 10:03:47
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.00it/s]
-------------- EPOCH   13/100 --------------
     Train loss: 0.00059619, accuracy: 99.99%
Validation loss: 0.07475528, accuracy: 98.25%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:02:43
      Timestamp: 2017/06/09 10:03:59
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.97it/s]
-------------- EPOCH   14/100 --------------
     Train loss: 0.00046983, accuracy: 99.99%
Validation loss: 0.06044000, accuracy: 98.39%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:02:54
      Timestamp: 2017/06/09 10:04:10
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.06it/s]
-------------- EPOCH   15/100 --------------
     Train loss: 0.00030913, accuracy: 100.00%
Validation loss: 0.06012980, accuracy: 98.22%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:03:05
      Timestamp: 2017/06/09 10:04:22
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.07it/s]
-------------- EPOCH   16/100 --------------
     Train loss: 0.00061189, accuracy: 99.99%
Validation loss: 0.05503106, accuracy: 98.48%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:03:17
      Timestamp: 2017/06/09 10:04:33
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.01it/s]
-------------- EPOCH   17/100 --------------
     Train loss: 0.00020143, accuracy: 100.00%
Validation loss: 0.05100803, accuracy: 98.59%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:03:28
      Timestamp: 2017/06/09 10:04:44
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.06it/s]
-------------- EPOCH   18/100 --------------
     Train loss: 0.00014925, accuracy: 100.00%
Validation loss: 0.06509451, accuracy: 98.58%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:03:39
      Timestamp: 2017/06/09 10:04:56
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.03it/s]
-------------- EPOCH   19/100 --------------
     Train loss: 0.00026115, accuracy: 99.99%
Validation loss: 0.04150585, accuracy: 98.83%
      Best loss: 0.04234268 at epoch 12
   Elapsed time: 00:03:51
      Timestamp: 2017/06/09 10:05:07
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.01it/s]
-------------- EPOCH   20/100 --------------
     Train loss: 0.00025054, accuracy: 99.99%
Validation loss: 0.03658258, accuracy: 98.99%
      Best loss: 0.04150585 at epoch 19
   Elapsed time: 00:04:03
      Timestamp: 2017/06/09 10:05:19
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 26.99it/s]
-------------- EPOCH   21/100 --------------
     Train loss: 0.00028971, accuracy: 99.99%
Validation loss: 0.06407166, accuracy: 98.41%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:04:14
      Timestamp: 2017/06/09 10:05:31
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.02it/s]
-------------- EPOCH   22/100 --------------
     Train loss: 0.00011762, accuracy: 100.00%
Validation loss: 0.03863846, accuracy: 98.93%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:04:26
      Timestamp: 2017/06/09 10:05:42
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.06it/s]
-------------- EPOCH   23/100 --------------
     Train loss: 0.00023333, accuracy: 99.99%
Validation loss: 0.03884849, accuracy: 98.95%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:04:37
      Timestamp: 2017/06/09 10:05:53
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.04it/s]
-------------- EPOCH   24/100 --------------
     Train loss: 0.00008937, accuracy: 100.00%
Validation loss: 0.05421620, accuracy: 98.50%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:04:48
      Timestamp: 2017/06/09 10:06:05
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.03it/s]
-------------- EPOCH   25/100 --------------
     Train loss: 0.00026975, accuracy: 99.99%
Validation loss: 0.04059058, accuracy: 98.88%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:05:00
      Timestamp: 2017/06/09 10:06:16
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.06it/s]
-------------- EPOCH   26/100 --------------
     Train loss: 0.00012874, accuracy: 100.00%
Validation loss: 0.04607462, accuracy: 98.76%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:05:11
      Timestamp: 2017/06/09 10:06:27
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.08it/s]
-------------- EPOCH   27/100 --------------
     Train loss: 0.00013468, accuracy: 100.00%
Validation loss: 0.05364396, accuracy: 98.54%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:05:22
      Timestamp: 2017/06/09 10:06:38
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.04it/s]
-------------- EPOCH   28/100 --------------
     Train loss: 0.00017276, accuracy: 100.00%
Validation loss: 0.04188826, accuracy: 98.84%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:05:34
      Timestamp: 2017/06/09 10:06:50
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.10it/s]
-------------- EPOCH   29/100 --------------
     Train loss: 0.00009000, accuracy: 100.00%
Validation loss: 0.04823944, accuracy: 98.70%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:05:45
      Timestamp: 2017/06/09 10:07:01
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.06it/s]
-------------- EPOCH   30/100 --------------
     Train loss: 0.00003416, accuracy: 100.00%
Validation loss: 0.05014061, accuracy: 98.50%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:05:56
      Timestamp: 2017/06/09 10:07:12
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:08<00:00, 27.05it/s]
-------------- EPOCH   31/100 --------------
     Train loss: 0.00012834, accuracy: 100.00%
Validation loss: 0.05004630, accuracy: 98.66%
      Best loss: 0.03658258 at epoch 20
   Elapsed time: 00:06:07
      Timestamp: 2017/06/09 10:07:24
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_24_conv1_k_5_conv1_p_0.8_conv2_d_64_conv2_k_5_conv2_p_0.8_fc3_p_0.5_fc3_size_480_fc4_p_0.5_fc4_size_252\best_epoch
Early stopping.
Best monitored loss was 0.03658258 at epoch 20.
=============================================
 Valid loss: 0.03658258, accuracy = 98.99%)
 Test loss: 0.13993206, accuracy = 96.86%)
 Total time: 00:06:08
  Timestamp: 2017/06/09 10:07:24
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_24_conv1_k_5_conv1_p_0.8_conv2_d_64_conv2_k_5_conv2_p_0.8_fc3_p_0.5_fc3_size_480_fc4_p_0.5_fc4_size_252\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\lenet__conv1_d_24_conv1_k_5_conv1_p_0.8_conv2_d_64_conv2_k_5_conv2_p_0.8_fc3_p_0.5_fc3_size_480_fc4_p_0.5_fc4_size_252\training_history.npz
In [21]:
_ = tu.train_model(X_train, y_train, X_valid, y_valid, X_test, y_test,
                  model=tu.sermanet, model_params=tu.params_sermanet)
========= train_model() arguments: ==========
resuming = False
model = <function sermanet at 0x000001E2F2D91F28>
model_params = {'conv2_d': 108, 'fc4_size': 100, 'conv2_k': 5, 'conv1_d': 108, 'conv1_k': 5, 'model_name': 'sermanet', 'num_classes': 43, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
learning_rate = 0.001
max_epochs = 100
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
=============================================
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\sermanet__conv1_d_108_conv1_k_5_conv1_p_0.9_conv2_d_108_conv2_k_5_conv2_p_0.8_fc4_p_0.5_fc4_size_100
{'conv2_d': 108, 'fc4_size': 100, 'conv2_k': 5, 'conv1_d': 108, 'conv1_k': 5, 'model_name': 'sermanet', 'num_classes': 43, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
================= TRAINING ==================
 Timestamp: 2017/06/09 10:07:26
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:29<00:00,  5.40it/s]
-------------- EPOCH    0/100 --------------
     Train loss: 0.29710005, accuracy: 93.60%
Validation loss: 0.44497574, accuracy: 89.21%
      Best loss: inf at epoch 0
   Elapsed time: 00:00:38
      Timestamp: 2017/06/09 10:08:04
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.27it/s]
-------------- EPOCH    1/100 --------------
     Train loss: 0.12010981, accuracy: 97.42%
Validation loss: 0.25480032, accuracy: 92.85%
      Best loss: 0.44497574 at epoch 0
   Elapsed time: 00:01:15
      Timestamp: 2017/06/09 10:08:41
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.27it/s]
-------------- EPOCH    2/100 --------------
     Train loss: 0.07292458, accuracy: 98.84%
Validation loss: 0.18637784, accuracy: 95.30%
      Best loss: 0.25480032 at epoch 1
   Elapsed time: 00:01:52
      Timestamp: 2017/06/09 10:09:18
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.27it/s]
-------------- EPOCH    3/100 --------------
     Train loss: 0.04057036, accuracy: 99.15%
Validation loss: 0.13313158, accuracy: 95.93%
      Best loss: 0.18637784 at epoch 2
   Elapsed time: 00:02:29
      Timestamp: 2017/06/09 10:09:55
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.28it/s]
-------------- EPOCH    4/100 --------------
     Train loss: 0.02512252, accuracy: 99.49%
Validation loss: 0.11260765, accuracy: 96.79%
      Best loss: 0.13313158 at epoch 3
   Elapsed time: 00:03:06
      Timestamp: 2017/06/09 10:10:32
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.27it/s]
-------------- EPOCH    5/100 --------------
     Train loss: 0.02064563, accuracy: 99.62%
Validation loss: 0.11380121, accuracy: 96.56%
      Best loss: 0.11260765 at epoch 4
   Elapsed time: 00:03:44
      Timestamp: 2017/06/09 10:11:09
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.28it/s]
-------------- EPOCH    6/100 --------------
     Train loss: 0.01731847, accuracy: 99.68%
Validation loss: 0.10509808, accuracy: 96.65%
      Best loss: 0.11260765 at epoch 4
   Elapsed time: 00:04:20
      Timestamp: 2017/06/09 10:11:46
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.27it/s]
-------------- EPOCH    7/100 --------------
     Train loss: 0.01673988, accuracy: 99.66%
Validation loss: 0.09734644, accuracy: 96.88%
      Best loss: 0.10509808 at epoch 6
   Elapsed time: 00:04:57
      Timestamp: 2017/06/09 10:12:23
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.28it/s]
-------------- EPOCH    8/100 --------------
     Train loss: 0.01276419, accuracy: 99.77%
Validation loss: 0.09295493, accuracy: 97.09%
      Best loss: 0.09734644 at epoch 7
   Elapsed time: 00:05:34
      Timestamp: 2017/06/09 10:13:00
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.28it/s]
-------------- EPOCH    9/100 --------------
     Train loss: 0.01020428, accuracy: 99.80%
Validation loss: 0.08104520, accuracy: 97.52%
      Best loss: 0.09295493 at epoch 8
   Elapsed time: 00:06:12
      Timestamp: 2017/06/09 10:13:37
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.29it/s]
-------------- EPOCH   10/100 --------------
     Train loss: 0.01066262, accuracy: 99.82%
Validation loss: 0.07642876, accuracy: 97.83%
      Best loss: 0.08104520 at epoch 9
   Elapsed time: 00:06:49
      Timestamp: 2017/06/09 10:14:14
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.28it/s]
-------------- EPOCH   11/100 --------------
     Train loss: 0.00901312, accuracy: 99.84%
Validation loss: 0.08857551, accuracy: 97.22%
      Best loss: 0.07642876 at epoch 10
   Elapsed time: 00:07:26
      Timestamp: 2017/06/09 10:14:51
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.29it/s]
-------------- EPOCH   12/100 --------------
     Train loss: 0.00794332, accuracy: 99.80%
Validation loss: 0.09517333, accuracy: 97.15%
      Best loss: 0.07642876 at epoch 10
   Elapsed time: 00:08:02
      Timestamp: 2017/06/09 10:15:28
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.29it/s]
-------------- EPOCH   13/100 --------------
     Train loss: 0.00469949, accuracy: 99.93%
Validation loss: 0.06483043, accuracy: 98.39%
      Best loss: 0.07642876 at epoch 10
   Elapsed time: 00:08:39
      Timestamp: 2017/06/09 10:16:05
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.29it/s]
-------------- EPOCH   14/100 --------------
     Train loss: 0.00517672, accuracy: 99.90%
Validation loss: 0.06755185, accuracy: 98.05%
      Best loss: 0.06483043 at epoch 13
   Elapsed time: 00:09:16
      Timestamp: 2017/06/09 10:16:42
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.29it/s]
-------------- EPOCH   15/100 --------------
     Train loss: 0.00394813, accuracy: 99.93%
Validation loss: 0.06112824, accuracy: 98.39%
      Best loss: 0.06483043 at epoch 13
   Elapsed time: 00:09:52
      Timestamp: 2017/06/09 10:17:18
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.29it/s]
-------------- EPOCH   16/100 --------------
     Train loss: 0.00325308, accuracy: 99.96%
Validation loss: 0.06750560, accuracy: 98.04%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:10:30
      Timestamp: 2017/06/09 10:17:55
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   17/100 --------------
     Train loss: 0.00276238, accuracy: 99.96%
Validation loss: 0.06599570, accuracy: 98.30%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:11:06
      Timestamp: 2017/06/09 10:18:32
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   18/100 --------------
     Train loss: 0.00416060, accuracy: 99.93%
Validation loss: 0.07053905, accuracy: 97.80%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:11:43
      Timestamp: 2017/06/09 10:19:08
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   19/100 --------------
     Train loss: 0.00392631, accuracy: 99.92%
Validation loss: 0.06306376, accuracy: 98.30%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:12:19
      Timestamp: 2017/06/09 10:19:45
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   20/100 --------------
     Train loss: 0.00221216, accuracy: 99.96%
Validation loss: 0.07416410, accuracy: 98.16%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:12:56
      Timestamp: 2017/06/09 10:20:21
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   21/100 --------------
     Train loss: 0.00278495, accuracy: 99.96%
Validation loss: 0.06626143, accuracy: 97.91%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:13:32
      Timestamp: 2017/06/09 10:20:58
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   22/100 --------------
     Train loss: 0.00206357, accuracy: 99.96%
Validation loss: 0.07468944, accuracy: 97.91%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:14:09
      Timestamp: 2017/06/09 10:21:34
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.24it/s]
-------------- EPOCH   23/100 --------------
     Train loss: 0.00179167, accuracy: 99.99%
Validation loss: 0.05790612, accuracy: 98.45%
      Best loss: 0.06112824 at epoch 15
   Elapsed time: 00:14:46
      Timestamp: 2017/06/09 10:22:12
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.17it/s]
-------------- EPOCH   24/100 --------------
     Train loss: 0.00182902, accuracy: 99.97%
Validation loss: 0.05682913, accuracy: 98.51%
      Best loss: 0.05790612 at epoch 23
   Elapsed time: 00:15:23
      Timestamp: 2017/06/09 10:22:49
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.12it/s]
-------------- EPOCH   25/100 --------------
     Train loss: 0.00178800, accuracy: 99.97%
Validation loss: 0.08047458, accuracy: 97.73%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:16:01
      Timestamp: 2017/06/09 10:23:27
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.15it/s]
-------------- EPOCH   26/100 --------------
     Train loss: 0.00216610, accuracy: 99.96%
Validation loss: 0.06799202, accuracy: 98.22%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:16:39
      Timestamp: 2017/06/09 10:24:05
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.20it/s]
-------------- EPOCH   27/100 --------------
     Train loss: 0.00234090, accuracy: 99.93%
Validation loss: 0.08851521, accuracy: 97.58%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:17:16
      Timestamp: 2017/06/09 10:24:42
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   28/100 --------------
     Train loss: 0.00134070, accuracy: 99.98%
Validation loss: 0.06512675, accuracy: 98.34%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:17:52
      Timestamp: 2017/06/09 10:25:18
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.31it/s]
-------------- EPOCH   29/100 --------------
     Train loss: 0.00165778, accuracy: 99.99%
Validation loss: 0.06783874, accuracy: 98.13%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:18:29
      Timestamp: 2017/06/09 10:25:55
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.31it/s]
-------------- EPOCH   30/100 --------------
     Train loss: 0.00180987, accuracy: 99.98%
Validation loss: 0.07840446, accuracy: 97.87%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:19:05
      Timestamp: 2017/06/09 10:26:31
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   31/100 --------------
     Train loss: 0.00087638, accuracy: 99.99%
Validation loss: 0.09269232, accuracy: 97.62%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:19:42
      Timestamp: 2017/06/09 10:27:08
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.31it/s]
-------------- EPOCH   32/100 --------------
     Train loss: 0.00172394, accuracy: 99.97%
Validation loss: 0.08182984, accuracy: 97.91%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:20:18
      Timestamp: 2017/06/09 10:27:44
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.31it/s]
-------------- EPOCH   33/100 --------------
     Train loss: 0.00123865, accuracy: 99.98%
Validation loss: 0.07845549, accuracy: 97.96%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:20:55
      Timestamp: 2017/06/09 10:28:21
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.31it/s]
-------------- EPOCH   34/100 --------------
     Train loss: 0.00074778, accuracy: 99.99%
Validation loss: 0.06919423, accuracy: 98.43%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:21:31
      Timestamp: 2017/06/09 10:28:57
100%|████████████████████████████████████████████████████████████████████████████████| 234/234 [00:28<00:00,  8.30it/s]
-------------- EPOCH   35/100 --------------
     Train loss: 0.00092423, accuracy: 99.99%
Validation loss: 0.07929316, accuracy: 98.19%
      Best loss: 0.05682913 at epoch 24
   Elapsed time: 00:22:08
      Timestamp: 2017/06/09 10:29:34
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\sermanet__conv1_d_108_conv1_k_5_conv1_p_0.9_conv2_d_108_conv2_k_5_conv2_p_0.8_fc4_p_0.5_fc4_size_100\best_epoch
Early stopping.
Best monitored loss was 0.05682913 at epoch 24.
=============================================
 Valid loss: 0.05682913, accuracy = 98.51%)
 Test loss: 0.18804120, accuracy = 96.14%)
 Total time: 00:22:11
  Timestamp: 2017/06/09 10:29:36
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\sermanet__conv1_d_108_conv1_k_5_conv1_p_0.9_conv2_d_108_conv2_k_5_conv2_p_0.8_fc4_p_0.5_fc4_size_100\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\sermanet__conv1_d_108_conv1_k_5_conv1_p_0.9_conv2_d_108_conv2_k_5_conv2_p_0.8_fc4_p_0.5_fc4_size_100\training_history.npz
In [29]:
fine_tuning=True
if not fine_tuning:
    _ = tu.train_model(X_train, y_train, X_valid, y_valid, X_test, y_test,
                  model=tu.sermanet_v2, model_params=tu.params_sermanet_v2)
else:
    X_train, y_train = tu.load_pickled_data(train_fname_FA, columns = ['features', 'labels'])
    X_valid, y_valid = tu.load_pickled_data(valid_fname_FA, columns = ['features', 'labels'])
    X_test, y_test = tu.load_pickled_data(test_fname, columns = ['features', 'labels'])
    print(X_train.shape, y_train.shape)
    print(X_valid.shape, y_valid.shape)
    print(X_test.shape, y_test.shape)
    
    _ = tu.train_model(X_train, y_train, X_valid, y_valid, X_test, y_test,
                  model=tu.sermanet_v2, model_params=tu.params_sermanet_v2, learning_rate=0.0001, resuming=True)
(1016396, 32, 32, 1) (1016396,)
(129030, 32, 32, 1) (129030,)
(12630, 32, 32, 1) (12630,)
========= train_model() arguments: ==========
resuming = True
model = <function sermanet_v2 at 0x000001E2F3177C80>
model_params = {'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
learning_rate = 0.0001
max_epochs = 100
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
=============================================
sermanet_v2__conv1_d_32_conv1_k_5_conv1_p_0.9_conv2_d_64_conv2_k_5_conv2_p_0.8_conv3_d_128_conv3_k_5_conv3_p_0.7_fc4_p_0.5_fc4_size_1024
-0x68eeac73a1a6c42a
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a
{'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Restored session from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
================= TRAINING ==================
 Timestamp: 2017/06/09 12:31:15
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:48<00:00, 15.95it/s]
-------------- EPOCH    0/100 --------------
     Train loss: 0.02475104, accuracy: 99.34%
Validation loss: 0.12579630, accuracy: 96.29%
      Best loss: inf at epoch 0
   Elapsed time: 00:04:55
      Timestamp: 2017/06/09 12:36:09
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:47<00:00, 17.45it/s]
-------------- EPOCH    1/100 --------------
     Train loss: 0.01278611, accuracy: 99.68%
Validation loss: 0.10770545, accuracy: 96.82%
      Best loss: 0.12579630 at epoch 0
   Elapsed time: 00:09:49
      Timestamp: 2017/06/09 12:41:03
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:46<00:00, 17.53it/s]
-------------- EPOCH    2/100 --------------
     Train loss: 0.00773200, accuracy: 99.82%
Validation loss: 0.09592463, accuracy: 97.12%
      Best loss: 0.10770545 at epoch 1
   Elapsed time: 00:14:41
      Timestamp: 2017/06/09 12:45:55
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH    3/100 --------------
     Train loss: 0.00499924, accuracy: 99.89%
Validation loss: 0.08452176, accuracy: 97.49%
      Best loss: 0.09592463 at epoch 2
   Elapsed time: 00:19:32
      Timestamp: 2017/06/09 12:50:46
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH    4/100 --------------
     Train loss: 0.00349669, accuracy: 99.93%
Validation loss: 0.07591092, accuracy: 97.78%
      Best loss: 0.08452176 at epoch 3
   Elapsed time: 00:24:23
      Timestamp: 2017/06/09 12:55:37
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH    5/100 --------------
     Train loss: 0.00241716, accuracy: 99.95%
Validation loss: 0.07660178, accuracy: 97.76%
      Best loss: 0.07591092 at epoch 4
   Elapsed time: 00:29:14
      Timestamp: 2017/06/09 13:00:29
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH    6/100 --------------
     Train loss: 0.00171894, accuracy: 99.97%
Validation loss: 0.07754694, accuracy: 97.81%
      Best loss: 0.07591092 at epoch 4
   Elapsed time: 00:34:05
      Timestamp: 2017/06/09 13:05:19
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH    7/100 --------------
     Train loss: 0.00121693, accuracy: 99.98%
Validation loss: 0.06577003, accuracy: 98.11%
      Best loss: 0.07591092 at epoch 4
   Elapsed time: 00:38:55
      Timestamp: 2017/06/09 13:10:09
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH    8/100 --------------
     Train loss: 0.00097829, accuracy: 99.99%
Validation loss: 0.06634695, accuracy: 98.09%
      Best loss: 0.06577003 at epoch 7
   Elapsed time: 00:43:46
      Timestamp: 2017/06/09 13:15:00
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH    9/100 --------------
     Train loss: 0.00074323, accuracy: 99.99%
Validation loss: 0.05999615, accuracy: 98.33%
      Best loss: 0.06577003 at epoch 7
   Elapsed time: 00:48:37
      Timestamp: 2017/06/09 13:19:51
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   10/100 --------------
     Train loss: 0.00053640, accuracy: 99.99%
Validation loss: 0.06183602, accuracy: 98.26%
      Best loss: 0.05999615 at epoch 9
   Elapsed time: 00:53:28
      Timestamp: 2017/06/09 13:24:42
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   11/100 --------------
     Train loss: 0.00041892, accuracy: 100.00%
Validation loss: 0.06672438, accuracy: 98.23%
      Best loss: 0.05999615 at epoch 9
   Elapsed time: 00:58:18
      Timestamp: 2017/06/09 13:29:32
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   12/100 --------------
     Train loss: 0.00035013, accuracy: 100.00%
Validation loss: 0.06123426, accuracy: 98.27%
      Best loss: 0.05999615 at epoch 9
   Elapsed time: 01:03:09
      Timestamp: 2017/06/09 13:34:23
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.59it/s]
-------------- EPOCH   13/100 --------------
     Train loss: 0.00025091, accuracy: 100.00%
Validation loss: 0.06013833, accuracy: 98.36%
      Best loss: 0.05999615 at epoch 9
   Elapsed time: 01:07:59
      Timestamp: 2017/06/09 13:39:14
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   14/100 --------------
     Train loss: 0.00025895, accuracy: 100.00%
Validation loss: 0.05654326, accuracy: 98.47%
      Best loss: 0.05999615 at epoch 9
   Elapsed time: 01:12:50
      Timestamp: 2017/06/09 13:44:04
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   15/100 --------------
     Train loss: 0.00021460, accuracy: 100.00%
Validation loss: 0.06430955, accuracy: 98.32%
      Best loss: 0.05654326 at epoch 14
   Elapsed time: 01:17:41
      Timestamp: 2017/06/09 13:48:55
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   16/100 --------------
     Train loss: 0.00015201, accuracy: 100.00%
Validation loss: 0.05645237, accuracy: 98.46%
      Best loss: 0.05654326 at epoch 14
   Elapsed time: 01:22:32
      Timestamp: 2017/06/09 13:53:46
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   17/100 --------------
     Train loss: 0.00016053, accuracy: 100.00%
Validation loss: 0.05354430, accuracy: 98.52%
      Best loss: 0.05645237 at epoch 16
   Elapsed time: 01:27:23
      Timestamp: 2017/06/09 13:58:37
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   18/100 --------------
     Train loss: 0.00011048, accuracy: 100.00%
Validation loss: 0.05289021, accuracy: 98.60%
      Best loss: 0.05354430 at epoch 17
   Elapsed time: 01:32:14
      Timestamp: 2017/06/09 14:03:28
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   19/100 --------------
     Train loss: 0.00011746, accuracy: 100.00%
Validation loss: 0.05507397, accuracy: 98.54%
      Best loss: 0.05289021 at epoch 18
   Elapsed time: 01:37:05
      Timestamp: 2017/06/09 14:08:20
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   20/100 --------------
     Train loss: 0.00010857, accuracy: 100.00%
Validation loss: 0.04987821, accuracy: 98.66%
      Best loss: 0.05289021 at epoch 18
   Elapsed time: 01:41:56
      Timestamp: 2017/06/09 14:13:10
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   21/100 --------------
     Train loss: 0.00008942, accuracy: 100.00%
Validation loss: 0.06212269, accuracy: 98.42%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 01:46:47
      Timestamp: 2017/06/09 14:18:01
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   22/100 --------------
     Train loss: 0.00009712, accuracy: 100.00%
Validation loss: 0.05552538, accuracy: 98.54%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 01:51:38
      Timestamp: 2017/06/09 14:22:52
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.60it/s]
-------------- EPOCH   23/100 --------------
     Train loss: 0.00007244, accuracy: 100.00%
Validation loss: 0.05849678, accuracy: 98.50%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 01:56:28
      Timestamp: 2017/06/09 14:27:42
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   24/100 --------------
     Train loss: 0.00006937, accuracy: 100.00%
Validation loss: 0.06084669, accuracy: 98.51%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:01:18
      Timestamp: 2017/06/09 14:32:33
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   25/100 --------------
     Train loss: 0.00005505, accuracy: 100.00%
Validation loss: 0.06179394, accuracy: 98.45%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:06:09
      Timestamp: 2017/06/09 14:37:23
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   26/100 --------------
     Train loss: 0.00004734, accuracy: 100.00%
Validation loss: 0.06093646, accuracy: 98.51%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:10:59
      Timestamp: 2017/06/09 14:42:13
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:45<00:00, 17.61it/s]
-------------- EPOCH   27/100 --------------
     Train loss: 0.00004377, accuracy: 100.00%
Validation loss: 0.05422828, accuracy: 98.60%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:15:49
      Timestamp: 2017/06/09 14:47:04
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:48<00:00, 17.35it/s]
-------------- EPOCH   28/100 --------------
     Train loss: 0.00003669, accuracy: 100.00%
Validation loss: 0.05520196, accuracy: 98.62%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:20:45
      Timestamp: 2017/06/09 14:51:59
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:51<00:00, 17.13it/s]
-------------- EPOCH   29/100 --------------
     Train loss: 0.00003791, accuracy: 100.00%
Validation loss: 0.05078053, accuracy: 98.75%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:25:42
      Timestamp: 2017/06/09 14:56:57
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:52<00:00, 17.10it/s]
-------------- EPOCH   30/100 --------------
     Train loss: 0.00003529, accuracy: 100.00%
Validation loss: 0.05426838, accuracy: 98.65%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:30:41
      Timestamp: 2017/06/09 15:01:55
100%|██████████████████████████████████████████████████████████████████████████████| 3971/3971 [03:52<00:00, 17.10it/s]
-------------- EPOCH   31/100 --------------
     Train loss: 0.00003687, accuracy: 100.00%
Validation loss: 0.05704716, accuracy: 98.60%
      Best loss: 0.04987821 at epoch 20
   Elapsed time: 02:35:39
      Timestamp: 2017/06/09 15:06:53
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\best_epoch
Early stopping.
Best monitored loss was 0.04987821 at epoch 20.
=============================================
 Valid loss: 0.04987821, accuracy = 98.66%)
 Test loss: 0.04602568, accuracy = 98.75%)
 Total time: 02:35:47
  Timestamp: 2017/06/09 15:07:02
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\training_history.npz
In [30]:
result = tu.train_model(X_train, y_train, X_valid, y_valid, X_test, y_test, 
                        model=tu.sermanet_v2, model_params=tu.params_sermanet_v2, resuming=True, max_epochs=-1)
========= train_model() arguments: ==========
resuming = True
model = <function sermanet_v2 at 0x000001E2F3177C80>
model_params = {'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
learning_rate = 0.001
max_epochs = -1
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
=============================================
sermanet_v2__conv1_d_32_conv1_k_5_conv1_p_0.9_conv2_d_64_conv2_k_5_conv2_p_0.8_conv3_d_128_conv3_k_5_conv3_p_0.7_fc4_p_0.5_fc4_size_1024
-0x68eeac73a1a6c42a
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a
{'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Restored session from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
================== TESTING ==================
 Timestamp: 2017/06/09 15:34:54
=============================================
 Valid loss: 0.04987821, accuracy = 98.66%)
 Test loss: 0.04602568, accuracy = 98.75%)
 Total time: 00:00:09
  Timestamp: 2017/06/09 15:35:02
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\training_history.npz

Train, Validate and Test the Model

A validation set can be used to assess how well the model is performing. A low accuracy on the training and validation sets imply underfitting. A high accuracy on the training set but low accuracy on the validation set implies overfitting.

In [31]:
### Train your model here.
### Calculate and report the accuracy on the training and validation set.
### Once a final model architecture is selected, 
### the accuracy on the test set should be calculated and reported as well.
### Feel free to use as many code cells as needed.

Investigating misclassified examples

In [32]:
valid_cp = result['valid_cp']
valid_ya = result['valid_ya']
valid_yp = result['valid_yp']
test_cp = result['test_cp']
test_ya = result['test_ya']
test_yp = result['test_yp']

print('Sanity check accuracy on validation set ', valid_cp.sum()/len(valid_cp))
print('There are {} misclassified examples in validation set'.format((1-valid_cp).sum()))

print('Sanity check accuracy on test set ', test_cp.sum()/len(test_cp))
print('There are {} misclassified examples in test set'.format((1-test_cp).sum()))
Sanity check accuracy on validation set  0.986576765093
There are 1732.0 misclassified examples in validation set
Sanity check accuracy on test set  0.98749010293
There are 158.0 misclassified examples in test set
In [33]:
def hist_misclass(cp, ya, yp, title=None):
    icp = 1-cp
    df = pd.DataFrame({'mistake': icp, 'actual_label': ya, 'pred_label': yp})
    df=df[df['mistake']==1]
    plt.figure(figsize=(20,4))
    a = 0.5
    df.actual_label.hist(bins=np.arange(n_classes+1)-0.5, alpha=a, normed=True)
    #plt.hist(y_valid, alpha=a, bins=np.arange(n_classes+1)-0.5, normed=True)
    plt.hist(y_train, alpha=a, bins=np.arange(n_classes+1)-0.5, normed=True)
    plt.xticks(range(n_classes), sign_df['SignName'], rotation='vertical')
    plt.legend(['mistake frequency', 
                #'actual lable frequency in validation set', 
                'actual lable frequency in training set'])
    plt.autoscale(enable=True, axis='x', tight=True)
    if title is not None:
        plt.title(title)
    plt.show()
    
    misdf = df.actual_label.value_counts()
    misdf = misdf.to_frame('mistake_count')
    misdf_with_names = pd.merge(sign_df, misdf, left_index=True, right_index=True)
    misdf_with_names['mistake_freq'] = misdf_with_names['mistake_count'] / misdf_with_names['mistake_count'].sum() 
    #display(misdf_with_names.sort_values(by='mistake_count', ascending=False).head(10))
    #print(misdf.index.astype(int))
        
def plot_misclass_images(X_data, cp, ya, yp, title=None):
    icp = 1-cp
    X_misclassified = X_data[icp.astype(bool)]
    print(X_misclassified.shape)
    print(ya[icp.astype(bool)][:35])
    print(yp[icp.astype(bool)][:35])

    N = 35
    M = X_misclassified.shape[0] // 35

    if M > 35:
        print('M is too big: ', M)
        M = 35

    plt.figure(figsize=(N,M))

    img_canvas = []

    for i in range(M):
        idx = range(i*N, (i+1)*N)
        img_canvas.append(np.concatenate(X_misclassified[idx], axis=1))

    img_canvas = np.concatenate(img_canvas, axis=0)

    if img_canvas.shape[-1]==1:
        plt.imshow(img_canvas.squeeze(), cmap='gray')
    elif img_canvas.shape[-1]==3:
        plt.imshow(img_canvas)
    else:
        plt.imshow(img_canvas[:,:,0], cmap='gray')
    
    if title is not None:
        plt.title(title)
    plt.show()
In [34]:
hist_misclass(cp=valid_cp, ya=valid_ya, yp=valid_yp, title='validation set results')
hist_misclass(cp=test_cp, ya=test_ya, yp=test_yp, title='test set results')
In [35]:
plot_misclass_images(X_data=X_valid, cp=valid_cp, ya=valid_ya, yp=valid_yp, title='validation set results')
plot_misclass_images(X_data=X_test, cp=test_cp, ya=test_ya, yp=test_yp, title='test set results')
(1732, 32, 32, 1)
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
[ 8.  8.  8.  2.  8.  8.  8.  8.  8.  1.  2.  4.  4.  4.  1.  1.  1.  1.
  1.  4.  1.  1.  1.  1.  1.  1.  4.  2.  4.  4.  4.  4.  4.  4.  4.]
M is too big:  49
(158, 32, 32, 1)
[ 30.  30.  30.   3.  18.  38.  26.  30.   4.   7.  26.   5.  25.  11.  12.
  18.   3.  21.  18.   5.  21.  40.   4.  18.   7.  21.  18.   2.   4.   5.
  27.  24.   5.  11.   8.]
[ 11.  23.  25.   5.  27.  40.  25.  19.   1.   8.  25.   2.  11.  30.  40.
  27.   5.  24.  27.   1.  18.  12.   1.  26.   8.  24.  11.   1.   1.   3.
  11.  18.   1.  30.   5.]
In [36]:
import itertools
from sklearn.metrics import confusion_matrix

def plot_confusion_matrix(cm, classes,
                          normalize=False,
                          title='Confusion matrix',
                          cmap=plt.cm.Blues):
    """
    This function prints and plots the confusion matrix.
    Normalization can be applied by setting `normalize=True`.
    """
    plt.imshow(cm, interpolation='nearest', cmap=cmap)
    plt.title(title)
    #plt.colorbar()
    tick_marks = np.arange(len(classes))
    plt.xticks(tick_marks, classes, rotation=90)
    plt.yticks(tick_marks, classes)

    if normalize:
        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
        print("Normalized confusion matrix")
    else:
        print('Confusion matrix, without normalization')

    #print(cm)

    thresh = cm.max() / 2.
    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
        plt.text(j, i, cm[i, j],
                 horizontalalignment="center",
                 color="white" if cm[i, j] > thresh else "black")

    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')

cnf_matrix = confusion_matrix(valid_ya, valid_yp)
np.set_printoptions(precision=2)
for i in range(cnf_matrix.shape[0]):# set diagonal line to 0 to better see actual confusion entries
    cnf_matrix[i][i]=0
class_names = sign_df.SignName
plt.figure(figsize=(20,20))
plot_confusion_matrix(cnf_matrix, classes=class_names, normalize=False, title='[Validation] Confusion matrix, without normalization')
plt.show()


cnf_matrix = confusion_matrix(test_ya, test_yp)
np.set_printoptions(precision=2)
for i in range(cnf_matrix.shape[0]):# set diagonal line to 0 to better see actual confusion entries
    cnf_matrix[i][i]=0
class_names = sign_df.SignName
plt.figure(figsize=(20,20))
plot_confusion_matrix(cnf_matrix, classes=class_names, normalize=False, title='[Test] Confusion matrix, without normalization')
plt.show()
Confusion matrix, without normalization
Confusion matrix, without normalization

Step 3: Test a Model on New Images

To give yourself more insight into how your model is working, download at least five pictures of German traffic signs from the web and use your model to predict the traffic sign type.

You may find signnames.csv useful as it contains mappings from the class id (integer) to the actual sign name.

Load and Output the Images

In [157]:
### Load the images and plot them here.
### Feel free to use as many code cells as needed.
import os, cv2, skimage
X_custom = []
y_custom = np.array([38, 36, 14, 17, 23, 17, 13, 18, 26, 28, 27])
N_custom = 11
plt.figure(figsize=(20,1))
for i in range(N_custom):
    image = cv2.imread(os.path.join('data', 'test_images', 'test_{0:0>3}.png'.format(i+1)))
    image = image[:,:,::-1]
    plt.subplot(1, N_custom, i+1)
    plt.imshow(image)
    plt.title(sign_df.loc[y_custom[i]]['SignName'])
    X_custom.append(image)
X_custom = np.asarray(X_custom)
X_custom_orig = X_custom.copy()
In [158]:
X_custom = tu.preprocess_data(X_custom)
Input shapes:  (11, 32, 32, 3)
Using gray
100%|████████████████████████████████████████████████████████████████████████████████| 11/11 [00:00<00:00, 7319.90it/s]
Output shapes:  (11, 32, 32, 1)

Predict the Sign Type for Each Image

In [182]:
### Run the predictions here and use the model to output the prediction for each image.
### Make sure to pre-process the images with the same pre-processing pipeline used earlier.
### Feel free to use as many code cells as needed.
result, top_k = tu.train_model(None, None, X_custom, y_custom, X_custom, y_custom,
                        model=tu.sermanet_v2, model_params=tu.params_sermanet_v2, resuming=True, max_epochs=-1,
                        return_top_k=True)
========= train_model() arguments: ==========
resuming = True
model = <function sermanet_v2 at 0x000001E299FE2950>
model_params = {'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
learning_rate = 0.001
max_epochs = -1
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
top_k = 5
return_top_k = True
plot_featuremap = False
=============================================
sermanet_v2__conv1_d_32_conv1_k_5_conv1_p_0.9_conv2_d_64_conv2_k_5_conv2_p_0.8_conv3_d_128_conv3_k_5_conv3_p_0.7_fc4_p_0.5_fc4_size_1024
-0x68eeac73a1a6c42a
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a
{'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Restored session from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
================== TESTING ==================
 Timestamp: 2017/06/09 21:16:31
=============================================
 Valid loss: 0.05124293, accuracy = 100.00%)
 Test loss: 0.05124293, accuracy = 100.00%)
 Total time: 00:00:01
  Timestamp: 2017/06/09 21:16:31
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\training_history.npz

Analyze Performance

In [183]:
### Calculate the accuracy for these 5 new images. 
### For example, if the model predicted 1 out of 5 signs correctly, it's 20% accurate on these new images.
#print(result)
print('Prediction accuracy: {}%'.format(result['test_cp'].mean()*100))
idx = np.arange(len(result['test_cp']))
print(idx[result['test_cp']==0])
Prediction accuracy: 100.0%
[]

Output Top 5 Softmax Probabilities For Each Image Found on the Web

For each of the new images, print out the model's softmax probabilities to show the certainty of the model's predictions (limit the output to the top 5 probabilities for each image). tf.nn.top_k could prove helpful here.

The example below demonstrates how tf.nn.top_k can be used to find the top k predictions for each image.

tf.nn.top_k will return the values and indices (class ids) of the top k predictions. So if k=3, for each sign, it'll return the 3 largest probabilities (out of a possible 43) and the correspoding class ids.

Take this numpy array as an example. The values in the array represent predictions. The array contains softmax probabilities for five candidate images with six possible classes. tk.nn.top_k is used to choose the three classes with the highest probability:

# (5, 6) array
a = np.array([[ 0.24879643,  0.07032244,  0.12641572,  0.34763842,  0.07893497,
         0.12789202],
       [ 0.28086119,  0.27569815,  0.08594638,  0.0178669 ,  0.18063401,
         0.15899337],
       [ 0.26076848,  0.23664738,  0.08020603,  0.07001922,  0.1134371 ,
         0.23892179],
       [ 0.11943333,  0.29198961,  0.02605103,  0.26234032,  0.1351348 ,
         0.16505091],
       [ 0.09561176,  0.34396535,  0.0643941 ,  0.16240774,  0.24206137,
         0.09155967]])

Running it through sess.run(tf.nn.top_k(tf.constant(a), k=3)) produces:

TopKV2(values=array([[ 0.34763842,  0.24879643,  0.12789202],
       [ 0.28086119,  0.27569815,  0.18063401],
       [ 0.26076848,  0.23892179,  0.23664738],
       [ 0.29198961,  0.26234032,  0.16505091],
       [ 0.34396535,  0.24206137,  0.16240774]]), indices=array([[3, 0, 5],
       [0, 1, 4],
       [0, 5, 1],
       [1, 3, 5],
       [1, 4, 3]], dtype=int32))

Looking just at the first row we get [ 0.34763842, 0.24879643, 0.12789202], you can confirm these are the 3 largest probabilities in a. You'll also notice [3, 0, 5] are the corresponding indices.

In [184]:
### Print out the top five softmax probabilities for the predictions on the German traffic sign images found on the web. 
### Feel free to use as many code cells as needed.
#print(top_k)
for i in range(N_custom):
    plt.figure(figsize=(13,3))
    plt.subplot(1,4,1)
    plt.imshow(X_custom_orig[i])
    plt.subplot(1,4,2)
    plt.imshow(X_custom[i,:,:,0], cmap='gray')
    plt.subplot(1,4,4)
    plt.barh(np.arange(5), top_k[0][0][i][::-1])
    plt.yticks(np.arange(5), sign_df.loc[top_k[0][1][i][::-1]]['SignName'])
    

Project Writeup

Once you have completed the code implementation, document your results in a project writeup using this template as a guide. The writeup can be in a markdown or pdf file.

Note: Once you have completed all of the code implementations and successfully answered each question above, you may finalize your work by exporting the iPython Notebook as an HTML document. You can do this by using the menu above and navigating to \n", "File -> Download as -> HTML (.html). Include the finished document along with this notebook as your submission.


Step 4 (Optional): Visualize the Neural Network's State with Test Images

This Section is not required to complete but acts as an additional excersise for understaning the output of a neural network's weights. While neural networks can be a great learning device they are often referred to as a black box. We can understand what the weights of a neural network look like better by plotting their feature maps. After successfully training your neural network you can see what it's feature maps look like by plotting the output of the network's weight layers in response to a test stimuli image. From these plotted feature maps, it's possible to see what characteristics of an image the network finds interesting. For a sign, maybe the inner network feature maps react with high activation to the sign's boundary outline or to the contrast in the sign's painted symbol.

Provided for you below is the function code that allows you to get the visualization output of any tensorflow weight layer you want. The inputs to the function should be a stimuli image, one used during training or a new one you provided, and then the tensorflow variable name that represents the layer's state during the training process, for instance if you wanted to see what the LeNet lab's feature maps looked like for it's second convolutional layer you could enter conv2 as the tf_activation variable.

For an example of what feature map outputs look like, check out NVIDIA's results in their paper End-to-End Deep Learning for Self-Driving Cars in the section Visualization of internal CNN State. NVIDIA was able to show that their network's inner weights had high activations to road boundary lines by comparing feature maps from an image with a clear path to one without. Try experimenting with a similar test to show that your trained network's weights are looking for interesting features, whether it's looking at differences in feature maps from images with or without a sign, or even what feature maps look like in a trained network vs a completely untrained one on the same sign image.

Combined Image

Your output should look something like this (above)

In [164]:
### Visualize your network's feature maps here.
### Feel free to use as many code cells as needed.

# image_input: the test image being fed into the network to produce the feature maps
# tf_activation: should be a tf variable name used during your training procedure that represents the calculated state of a specific weight layer
# activation_min/max: can be used to view the activation contrast in more detail, by default matplot sets min and max to the actual min and max values of the output
# plt_num: used to plot out multiple different weight feature map sets on the same block, just extend the plt number for each new feature map entry

def outputFeatureMap(image_input, tf_activation, activation_min=-1, activation_max=-1 ,plt_num=1):
    # Here make sure to preprocess your image_input in a way your network expects
    # with size, normalization, ect if needed
    # image_input =
    # Note: x should be the same name as your network's tensorflow data placeholder variable
    # If you get an error tf_activation is not defined it may be having trouble accessing the variable from inside a function
    activation = tf_activation.eval(session=sess,feed_dict={x : image_input})
    featuremaps = activation.shape[3]
    plt.figure(plt_num, figsize=(15,15))
    for featuremap in range(featuremaps):
        plt.subplot(6,8, featuremap+1) # sets the number of feature maps to show on each row and column
        plt.title('FeatureMap ' + str(featuremap)) # displays the feature map number
        if activation_min != -1 & activation_max != -1:
            plt.imshow(activation[0,:,:, featuremap], interpolation="nearest", vmin =activation_min, vmax=activation_max, cmap="gray")
        elif activation_max != -1:
            plt.imshow(activation[0,:,:, featuremap], interpolation="nearest", vmax=activation_max, cmap="gray")
        elif activation_min !=-1:
            plt.imshow(activation[0,:,:, featuremap], interpolation="nearest", vmin=activation_min, cmap="gray")
        else:
            plt.imshow(activation[0,:,:, featuremap], interpolation="nearest", cmap="gray")
In [186]:
result, top_k = tu.train_model(None, None, X_custom, y_custom, X_custom, y_custom,
                        model=tu.sermanet_v2, model_params=tu.params_sermanet_v2, resuming=True, max_epochs=-1,
                        return_top_k=True, plot_featuremap=True)
========= train_model() arguments: ==========
resuming = True
model = <function sermanet_v2 at 0x000001E3453B0620>
model_params = {'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
learning_rate = 0.001
max_epochs = -1
batch_size = 256
early_stopping_enabled = True
early_stopping_patience = 10
log_epoch = 1
print_epoch = 1
top_k = 5
return_top_k = True
plot_featuremap = True
=============================================
sermanet_v2__conv1_d_32_conv1_k_5_conv1_p_0.9_conv2_d_64_conv2_k_5_conv2_p_0.8_conv3_d_128_conv3_k_5_conv3_p_0.7_fc4_p_0.5_fc4_size_1024
-0x68eeac73a1a6c42a
model dir: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a
{'conv2_d': 64, 'fc4_size': 1024, 'conv2_k': 5, 'conv1_d': 32, 'conv1_k': 5, 'conv3_k': 5, 'model_name': 'sermanet_v2', 'conv3_p': 0.7, 'num_classes': 43, 'conv3_d': 128, 'fc4_p': 0.5, 'conv2_p': 0.8, 'conv1_p': 0.9}
INFO:tensorflow:Restoring parameters from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Restored session from C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
================== TESTING ==================
 Timestamp: 2017/06/09 21:18:41
=============================================
 Valid loss: 0.05124293, accuracy = 100.00%)
 Test loss: 0.05124293, accuracy = 100.00%)
 Total time: 00:00:01
  Timestamp: 2017/06/09 21:18:41
Model file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\model_cpkt
Train history file: C:\Users\dingran\github\CarND-Traffic-Sign-Classifier-Project\models\-0x68eeac73a1a6c42a\training_history.npz
In [ ]: